su
# install git
yum install -y git
yum install -y nodejs
yum install -y mysql
yum install -y mysql-server
yum install -y mysql-devel
service mysqld restart
yum install -y nginx
yum install -y redis

# install rvm
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm install ruby-2.2.0

# add user
useradd www
passwd www
# add to sudo
cd /etc/sudoers.d
touch add_www
chmod 777 add_www
echo "www ALL=(ALL) ALL" > add_www
chmod 400 add_www
# login as www
su www

root_path="/home/www"

# dir for unicorn.express.sock
if [ ! -d "${root_path}/sockets" ]; then
  #statements
  mkdir "${root_path}/sockets"
fi

cd $root_path

# git pull express
if [ ! -d "${root_path}/express" ]; then
  #statements
  sudo git clone http://xiaotie@office.cgz-invest.com:81/xiaotie/express.git
  mkdir express/tmp
  mkdir express/tmp/pids
  cd express
  bundle install
  mkdir public/assets
  mkdir public/assets/images
  ruby bin/reset_db
  # redis-cli: config set requirepass redis-123456
else
  cd express
  git pull origin master
fi

if [ ! -d "/etc/nginx/sites-available" ]; then
  sudo mkdir /etc/nginx/sites-available
  cp express /etc/nginx/sites-available/express
fi

if [ ! -d "/etc/nginx/sites-enabled" ]; then
  sudo mkdir /etc/nginx/sites-enabled
  ln -s /etc/nginx/sites-available/express /etc/nginx/sites-enabled/express
fi